//
package com.mdd.common.util;
//

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.mdd.common.plugin.sms.engine.AliSms;
import org.apache.commons.math3.util.Pair;

import java.util.HashMap;
import java.util.Map;

//
public class SmsUtil {

    /**
     * 阿里云发送短信
     * @param phone
     * @param templateId  阿里云短信模板id
     * @param param 入参：{\"code\":\"123456\"}
     * @return
     */
    public static Pair<Integer, String> sendAliyunSMS(String phone, String templateId, Map<String, String> param) {
        if(param==null || param.isEmpty()){
            return null;
        }
        Map<String, String> map = new HashMap<>();
        map.put("app_key", "LTAI5t6J3udSCwjEh8kPrSTd");
        map.put("secret_key", "5gbOEgbhHzNyrcW0meMACetgn9kY4X");
        map.put("sign", "羊羊领企");
        AliSms aliSms = new AliSms(map);
//        Map<String, String> param = new HashMap<>();
//        param.put("code", code);
        JSON json = JSON.parseObject(JSON.toJSONString(param));
        String responseData = aliSms.setMobile(phone)
                .setTemplateId(templateId)
                .setTemplateParams(json.toString())
                .send();
        JSONObject res = JSONObject.parseObject(responseData);
        if (res.get("Code").equals("OK") && res.get("Message").equals("OK")) {
            return new Pair<Integer,String>(2,responseData);
        }
        return new Pair<Integer,String>(1,responseData);
    }

    public static void main(String[] args) {
        Map<String, String> param = new HashMap<>();
        param.put("code", "123456");

        Pair<Integer, String> pair = sendAliyunSMS("17600135385", "SMS_316305245", param);
        System.out.println(pair.getKey()+"========================="+pair.getValue());

//        Map<String, String> map = new HashMap<>();
//        map.put("app_key", "LTAI5t6J3udSCwjEh8kPrSTd");
//        map.put("secret_key", "5gbOEgbhHzNyrcW0meMACetgn9kY4X");
//        map.put("sign", "羊羊领企");
//        AliSms aliSms = new AliSms(map);
////        String sms316305245 = aliSms.setMobile("17600135385")
////        String sms316305245 = aliSms.setMobile("18611171109")
//        String sms316305245 = aliSms.setMobile("13462772104")
//                .setTemplateId("SMS_316305245")
//                .setTemplateParams("{\"code\":\"123456\"}")
//                .send();
//        System.out.println(sms316305245);

    }


    public static class TEMPLATE{
        //test
        public static final String SMS_test = "SMS_316305245";
        //重置密码
        public static final String SMS_reset_password = "SMS_483985212";
        //绑定/修改手机号码
        public static final String SMS_change_phone = "SMS_484020191";
        //手机号验证码登录
        public static final String SMS_login = "SMS_484090225";
        //企业认证/绑定企业
        public static final String SMS_enterprise_certification = "SMS_486620387";
        //注销账户
        public static final String SMS_unsubscribe = "SMS_487225156";



    }





}